﻿namespace MessengerSample
{
    using System;
    using System.Globalization;
    using System.Windows;
    using System.Windows.Data;

    using Microsoft.Live.Messenger;

    public class PresenceToFriendlyNameConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            IMAddressPresence presence = (IMAddressPresence)value;

            string displayName = presence.DisplayName;

            if (String.IsNullOrEmpty(displayName))
            {
                displayName = presence.IMAddress.Address;
            }

            return displayName;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}